<?

$status_map = array('0'=>'Unapproved Registration','1'=>'Unapproved Renewal','2'=>'Unapproved Tranfer','3'=>'Unapproved Change','4'=>'Approved','5'=>'Rejected','6'=>'Suspended','7'=>'Transferring','8'=>'Transfer Fail','9'=>'Domain Expired',''=>'-');
$domain_list = list_reseller_domains_($GLOBALS['id']);

$params[sid] = $GLOBALS['sid'];
$params[action] = 'details_domain';

$params[domain_action] = 'whois';
$details_url_whois = "$GLOBALS[baseURL]/$GLOBALS[webDIR]/?".encode_params($params);

$params[domain_action] = 'dns';
$details_url_dns = "$GLOBALS[baseURL]/$GLOBALS[webDIR]/?".encode_params($params);

unset($params[domain_action]);
$params[action] = 'emails';
$emails_url = "$GLOBALS[baseURL]/$GLOBALS[webDIR]/?".encode_params($params);

$domain_type = array('norcp','rcpnomdns','rcpmdns');

$p1 = $GLOBALS['dns_products']->product[($GLOBALS['rp_products']['p1'])];
$p2 = $GLOBALS['dns_products']->product[($GLOBALS['rp_products']['p2'])];

if($domain_list){
        foreach($domain_list as $dom=>$arr){
                if($arr['dns_purchase_id']){
                        $private_dns = true;
                        break;
                }
        }
	$tbl = "<table class=bTable cellspacing=0 cellspacing=0 width=100%>
			<tr>
				<!--<th>X</th>-->
				<th>Domain</th>
				<th>Status</th>
				<th>DNS Check</th>
				<!--<th>Whois</th>-->
				<th>Expires on</th>
				<th>Take Action</th>
			</tr>";

	foreach($domain_list as $dom=>$arr){
		if($arr['rp_product_id']){
			if($arr['dns_purchase_id']){
				$list_dns_domains[] = $arr['dns_dom_id'];
				$query = "SELECT ds.ns_type, ds.mail_server, p.rp_product_id, ds.dns_dom_id, ds.dns_dom_name FROM dns_cluster.domain_settings ds LEFT JOIN purchases p ON(ds.dns_purchase_id=p.purchase_id) WHERE ds.dns_purchase_id=".$arr['dns_purchase_id'];
				$GLOBALS['master_db']->query($query);
				if($GLOBALS['master_db']->error){
					mail('errors@bastun.net', 'Could Not Get Private DNS rp_product_id', $query);
				}

				$dns_rp_product = $GLOBALS['master_db']->getNext();
				$tmp = array_flip($GLOBALS['rp_products']);
				$tmp1 = array_flip($GLOBALS['ns_types']);

				$renew_params = 'domain::renewal_'.$dom;
				$renew_params .= '|products::'.$tmp[($dns_rp_product['rp_product_id'])];
				$renew_params .= '|ns_type::'.$tmp1[($dns_rp_product['ns_type'])];
				$renew_params .= $dns_rp_product['mail_server'] == 't' ? '|mail_server::yes' : '';

				$domain_list[$dom][$type] = 'rcpmdns';
				$rcpmdns = true;

				$select = "
					<select name='dom_act' ".(!in_array($arr['flags'], array(4,9)) ? ' disabled ' : '')." onChange=\"SelectEvent(this);\">
						<option value=\"\">
						<option value=\"renewalServices('$renew_params')\">Renew
						<option value=\"fSubmit('$details_url_whois','$dom');\">Edit Whois
						<option value=\"LoadPage('managednsDomains',''); var timeoutID = setTimeout('document.getElementById($dns_rp_product[dns_dom_id]).selected = true; LoadDnsDomainInfo(\'dns_dom_id::$dns_rp_product[dns_dom_id]\');', 3000);\">Manage DNS
						<!--<option value='new_owner'>New Owner-->
						<option value=\"document.location.href = '$emails_url';\">Set E-mails
					</select>
				";
			}else{
				$tmp = array_flip($GLOBALS['rp_products']);
				$domain_list[$dom][$type] = 'rcpnomdns';

				if(strtotime($arr['expire_date']) - strtotime("+1 year") > 0){
					$add_mdns_params = 'domain::addmdns2_'.$dom;
				}else{
					$add_mdns_params = 'domain::addmdns1_'.$dom;
				}

				$rcpnomdns = true;
				$select = "
					<select name='dom_act' ".(!in_array($arr['flags'], array(4,9)) ? ' disabled ' : '')." onChange=\"SelectEvent(this);\">
						<option value=\"\">
						<option value=\"renewalServices('domain::renewal_".$dom."|products::".$tmp[($arr['rp_product_id'])]."')\">Renew
						<option value=\"fSubmit('$details_url_dns','$dom');\">Edit Name Servers
						<option value=\"fSubmit('$details_url_whois','$dom');\">Edit Whois
						".($private_dns ? "" : "<option value=\"goAddMNDS('$add_mdns_params');\">Add Private DNS")."
						<!--<option value='new_owner'>New Owner-->
						<option value=\"document.location.href = '$emails_url';\">Set E-mails
					</select>
				";
			}
		}else{
			$domain_list[$dom][$type] = 'norcp';
			$tmp_split_dom = explode('.', $dom);
			if(count($tmp_split_dom) == 2 and in_array($tmp_split_dom[1],array('com','net','org','info','us','biz'))){
				$transfer_flag = true;
			}
			$norcp = true;
			$select = "
				<select name='dom_act' onChange=\"SelectEvent(this);\">
					<option value=\"\">
					".($transfer_flag ?  "<option value=\"goTransfer('$dom');\">Transfer" : "")."
					<option value=\"fSubmit('$details_url_whois','$dom');\">View Whois
					<option value=\"document.location.href = '$emails_url';\">Set E-mails
					<option value=\"if(confirmSubmit('Are you shure you want to delete the selected domain?')){ delDomains('domains::$dom'); }\">Delete
				</select>
			";
		}
		$tbl .= "<tr>
			<!--<td><input type=radio name=domains value='$dom'></td>-->
			<td ".($arr['dns_purchase_id'] ? ' style="padding-left:10px;"><img align="absmiddle" src="domain/images/ico_managed_dns_orange.gif" alt="Added DNS" width="14" height="14" border="0"> ' : 'style="padding-left:24px;"> ')."<a href='http://$dom' target=_blank>$dom</a></td>
			<td align=center>".($status_map[($arr['flags'])])."</td>
			<td align=center>".(dns_check($dom) ? '<img align="absmiddle" src="domain/images/ok.gif" alt="YES" width="11" height="17" border="0">' : '<img align="absmiddle" src="domain/images/ok_no_02.gif" alt="NO" width="11" height="17" border="0">').($arr[flags]==4 ? "<!--<a href='#' onClick=\"fSubmit('$details_url_dns','$dom');return false;\">[change]</a>-->" : "")."</td>
			<!--<td align=center><a href='#' onClick=\"fSubmit('$details_url_whois','$dom');return false;\">".($arr[flags]==4 ? '[change]' : '[view]')."</a></td>-->
			<td align=center>".(($arr[flags]==4 or $arr[flags]==9) ? "[".date('m/d/Y',strtotime($arr[expire_date]))."]" : '-')."</td>
			<td align=left>$select</td>
		</tr>
		";
	}
	$tbl .= '</table><input type=hidden name="add_param">';
	$tbl = "<p>Manage your domain(s) with the available controls below:</p>".
			$tbl.
			'<!--<p align="center"><input type="submit" value="Set DNS &amp; Mail Server">&nbsp;&nbsp;&nbsp;<input type="submit" value="Renew Domain">&nbsp;&nbsp;&nbsp;<input type="button" value="Delete Domain" onClick="if(confirmSubmit(\'Are you shure you want to delete the selected domain?\')){delDomains(fetchForm());}return false;"></p>--><br />';
}else{
	$nodomain = true;
}


if($rcpmdns){
	$div_block = 'rcpmdns';

	$dns_domains_list = list_reseller_dns_domains($GLOBALS['id']);
/*
	$tbl2 = "<table class=bTable cellspacing=0 cellspacing=0 width=100%><tr>
		<th>X</th>
		<th>Domain</th>
		<th>DNS Package</th>
		<th>Status</th>
		<th>Expires on</th>
		<th>Take Action</th>
	</tr>";
*/
	foreach($dns_domains_list as $k => $v){
		if($v[checked] == 't'){
			$select2 .= "<option value=\"LoadDnsDomainInfo('dns_dom_id::$v[dns_dom_id]');\" id='$v[dns_dom_id]'>$v[dns_dom_name]</option>";
		}

/*
        	$tmp = getRpProductByPurchaseId($v['dns_purchase_id']);
	        $dns_package = $tmp['name'];
		$status = ($v[enabled] == 't' ? '<font color=green><b>Enabled</b></font>' : '<font color=red><b>Disabled</b></font>');

		$select = "<select name=take_action ".($v[checked] == 'f' ? ' disabled ' : '').">
			<option></option>
			<option value=renewal>Renewal</option>";
		$select .= ($v[enabled] == 't' ? "<option value=enabled_f><font color=red>Disable</font></option>" : "<option value=enabled_t><font color=green>Enabled</font></option>" );
		$select .= ($v['mail_server'] == 'f' ? "<option value=mail_server_t>Activate Mail Server</option>" : '');
		$select .= "</select>";

		$tbl2 .= "<tr>
			<td align=center><a href='#' onClick='expandMDNS($v[dns_dom_id]);return false;'>[expand]</a></td>
			<td align=center><a href='http://$v[dns_dom_name]' target='_blank'>$v[dns_dom_name]</a></td>
			<td>$dns_package</td>
			<td>$status</td>
			<td align=center>".date('m/d/Y', strtotime($tmp[expire_date]))."</td>
			<td>$select</td>
		</tr>";
*/
	}
//	$tbl2 .= '</table>';
	$select2 = "<select name=dns_doms onChange=\"SelectEvent(this);\"><option value=\"\"></option>".$select2."</select>";

	if($GLOBALS['dns_dom_id'] and is_numeric($GLOBALS['dns_dom_id'])){
		$dom_info = managedDNSdomInfo($GLOBALS['dns_dom_id']);
	}
}else{
	$div_block = 'rcpnomdns';
}

?>
<form id='sform' name='sform' method='post' onSubmit='return false;'>
<div id='rcpnomdns' style="display:<? echo($div_block == 'rcpnomdns' ? 'block' : 'none'); ?>;">
   <br />
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td align="left" style="padding:none;"><strong>Your own private name servers (Private DNS Cluster)</strong></td>
       <td align="right" valign="top"><a href="domain/faq.html" target="_blank">Help/ F.A.Q.</a></td>
	   <td align="right"><a href="domain/faq.html?tab=tutorials" target="_blank">Tutorials</a></td>
     </tr>
   </table>
   <p>The Private DNS Cluster is a reseller utility designed to help you create a unique web hosting store and brand awareness. We highly recommend that you use your own private name servers for the domains of your clients. If you do so, your reseller anonymity and brand awareness are more certain.</p>
   <p>An example of a private DNS is given below:<br>
     <strong>ns1.your-private-brand.com<BR />
   ns2.your-private-brand.com</strong></p>
   <p><strong>How does your private DNS cluster work?</strong><br><br>
   The Private DNS Cluster involves name servers, which you choose to register. They will be allocated to your clients. domain names' DNS records. All your clients, regardless of the server they are hosted on, can use your DNS to resolve their domains names.</p>
   <p><strong>We offer 2 packages for you to choose from:</strong></p>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td><table class='bTable' cellspacing=0 cellpadding=0 width=100%>
			  <tr>
				<th align="left">&raquo; Private DNS 1</th>
			  </tr>
			  <tr>
				<td ><p style="padding-left:15px;"><img align="absmiddle" src="domain/images/ok.gif" alt="OK" width="14" height="17">&nbsp;&nbsp;<strong style="font-size:12px;">ONE DEDICATED IP</strong><br>
				<img align="absmiddle" src="domain/images/ok.gif" alt="OK" width="14" height="17">&nbsp;&nbsp;<strong style="font-size:12px;">ONE SHARED IP</strong></p>
				<div style="background-color:#dcdcdc">&nbsp;<strong>Example:</strong></div>
				<br>
				<strong>ns1.your-private-brand.com</strong><br>
				<em>(uses a <span class="red">Dedicated IP</span> Address)</em><br>
				<strong>ns2.your-private-brand.com</strong><br>
				<em>(uses a Shared IP Address)</em><br /><br />
				<div style="height:1px; background:url(domain/images/dots_grey_line_01.gif); background-repeat:repeat-x;"></div>
				<br />
				<table style="border:none;" width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td style="border:none;"><strong>Price:</strong>  <strong style="font-size:18px;">$<? echo sprintf("%01.2f", $p1->getPriceByType()); ?></strong> <strong>/year</strong></td>
					<td  style="border:none;" align="right"><input type="submit" value="&nbsp;SELECT&nbsp;" onClick="loadPlan('p1');"></td>
				  </tr>
				</table>
				</td>
			  </tr>
			</table></td>
		<td width="10">&nbsp;</td>
		<td><table class='bTable' cellspacing=0 cellpadding=0 width=100%>
			  <tr>
				<th align="left">&raquo; Private DNS 2 (Recommended)</th>
			  </tr>
			  <tr>
				<td ><p style="padding-left:15px;"><br>
				  <img align="absmiddle" src="domain/images/ok.gif" alt="OK" width="14" height="17">&nbsp;&nbsp;<strong style="font-size:12px;"><span class="red">TWO</span> DEDICATED IPs</strong></p>
				<div style="background-color:#dcdcdc">&nbsp;<strong>Example:</strong></div>
				<br>
				<strong>ns1.your-private-brand.com</strong><br>
				<em>(uses a <span class="red">Dedicated IP</span> Address)</em><br>
				<strong>ns2.your-private-brand.com</strong><br>
				<em>(uses a <span class="red">Dedicated IP</span> Address)</em><br /><br />
				<div style="height:1px; background:url(domain/images/dots_grey_line_01.gif); background-repeat:repeat-x;"></div>
				<br />
				<table style="border:none;" width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td style="border:none;"><strong>Price:</strong>  <strong style="font-size:18px;">$<? echo sprintf("%01.2f", $p2->getPriceByType()); ?></strong> <strong>/year</strong></td>
					<td style="border:none;" align="right"><input type="submit" value="&nbsp;SELECT&nbsp;" onClick="loadPlan('p2');"></td>
				  </tr>
				</table>
				</td>
			  </tr>
			</table></td>
	  </tr>
	</table>
	<br />
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td width="30"><img src="domain/images/ico_free_mail_server.gif" alt="Free E-Mail Server" width="27" height="32" hspace="5" align="absmiddle"></td>
		<td><strong>Hint:</strong> When you activate a Private DNS package you get a <a href="https://secure.resellerspanel.com/login/domain/faq.html?tab=mail_cluster" target="_blank">FREE e-mail server</a> too. Let your clients receive and send emails easier!<br>
		Example of POP3/SMTP mail server: <strong>mail.your-private-brand.com</strong></td>
	  </tr>
	</table>
</div>
<div id="rcpmdns" style="display:<? echo($div_block == 'rcpmdns' ? 'block' : 'none'); ?>;">
	<br />
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td align="left" style="padding:0px;"><strong>Your own private name servers (Private DNS Cluster)</strong></td>
		<td align="right" valign="top"><a href="domain/faq.html" target="_blank">Help/ F.A.Q.</a></td>
		<td align="right"><a href="domain/faq.html?tab=tutorials" target="_blank">Tutorials</a></td>
	  </tr>
	</table>
	<br />
	<table cellspacing="0" cellpadding="0" width="100%">
		<tr>
			<td>Manage DNS for: &nbsp&nbsp<? echo $select2; ?></td>
			<td id='dns_expires_on'></td>
			<td id='renew_button'></td>
		<tr>
		<tr>
			<td colspan=3><div id='dns_dom_info'></div></td>
		</tr>
	</table>
	<? //echo $tbl2; ?>
	<div id='dns_warrning' style='display:none;'>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_error_table">
			<tr>
				<td class="order_error_table_th" height="40" colspan=2><font color="#FFFF00">WARNING!</font></td>
			</tr>
                          <tr>
                                <td width="28" style="padding: 5 2 5 2;" valign="top"><img src="domain/images/attention.gif" width="18" height="16"></td>
                                <td style="padding: 5 2 5 2;">
					<p><strong class="red"><span id='package_name_warring'></span> </strong> @ <strong>$<span id='package_price_warring'></span></strong>/year (<span id='num_ips_warring'></span> Dedicated IP(s)) will expire after <strong><span id='num_days_warring'></span> days</strong> (on <span id='expire_date_warrning'></span>)! <strong class="red">*</strong><br></p>
					<p><strong class="red">*</strong><br />You have <span id='dns_clients'><span> clients using it for their domains!<br /> Failure to renew it might cause a total loss of all you profits due. <a href="#">more info</a> . </p>
				</td>
                          </tr>
                        </table>
                        <br />
	</div>
	<div id='dns_domain' style='display:none;'>
	<table class="selected_dns" width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td><strong class="red"><span id='package_name'></span> </strong> @ <strong>$<span id='package_price'></span></strong>/year
			 for <span class="grey"><br><strong id='domain_name'></strong> (<span id='num_ips'></span> Dedicated IP(s))</span>
			</td>
			<td align=right><span><input type='submit' value='DNS Records' onClick="changeARecord(document.getElementById('current_dns_dom_id').value);"> </span><span id="dns_dom_action"></span><span><input type='hidden' name='current_dns_dom_id' id='current_dns_dom_id'></span></td>
		</tr>
<? /*
		<tr>
			<td colspan=2>
				<b>Store Settings: </b><input type="checkbox" name="open_store" id="open_store" onClick="store_settings(this.checked);" value="yes">
Open Store @ <input type="text" name="store_a_record" id="store_a_record">
<input type=button value="Change" OnClick="change_store_settings(('take_action::change_a_record|' + fetchForm()));">
			<td>
		</tr>
*/ ?>
	</table>
	<br />
	</div>
	<div id='dns_dom_table'>
	</div>
	<br />
	<? echo $tbl; ?>
<? /*
	<p align="center"><input type="submit" value="<?=translate('add_new_dns_package')?>" onClick="LoadPage('registerDomains','stepPage::Step1');"><br />&nbsp;</p>
	<br />
*/ ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr>
   <td align="left" style="padding:0px;"><strong><font color="#006600">Enabled</font> - This Private DNS is currently active.</strong></td>
   <td align="right" valign="top"></td>
   </tr>
   </table>
   All your new and existing customers will use the private name servers leased by you:<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dns1.your-private-brand.com<br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dns2.your-private-brand.com<br />
   for the domains, which they register, transfer or host.
   <br /><br />
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr>
   <td align="left" style="padding:0px;"><strong><font color="FF0000">Disabled</font> - This Private DNS is NOT currently active.<font color="FF0000">*</font></strong></td>
   <td align="right" valign="top"></td>
   </tr>
   </table>
   All your new customers will use the default DNSes offered by us:<br />
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dns1.supremecenterXX.com<br />
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dns2.supremecenterXX.com<br />
   for the domains, which they register, transfer or host.
   <p><font color="FF0000">*</font> &quot;Not Active&quot; does not mean that the DNSes <strong>dns1.your-private-brand.com</strong> &amp; <strong>dns2.your-private-brand.com</strong> are OFFLINE. The Private DNS leased by you will continue to work for all your existing customers who use your chosen DNSes for their domains' settings. Only new requests for registration, transfer or hosting of domain(s) will use our default DNSes until you re-activate your Private DNS.</p>
<p>
        <img align="absmiddle" src="domain/images/ico_managed_dns_orange.gif" alt="Added DNS" width="14" height="14" border="0">
 - Private DNS has been added for this domain name. You can modify the service's settings from the Private DNS section.
</p>
<p>
        <img align="absmiddle" src="domain/images/ok.gif" alt="YES" width="11" height="17" border="0">
 - This domain name has the required DNSes set in order to operate with our system.
</p>
<p>
        <img align="absmiddle" src="domain/images/ok_no_02.gif" alt="NO" width="11" height="17" border="0">
 - This domain name does not have the required DNSes set in order to operate with our system.
Please update them to the following ones: <b>dns1.supremecenter.com</b> and <b>dns2.supremecenter.com</b>
</p>
</div>
</form>
